import { customRef } from "vue";
export function debounceRef<T>(value: T, delay = 100) {
  // 自定义ref 关键 收集依赖 tarck， 派发更新 trigger
  let timer: any = null

  return customRef((track, trigger) => ({
    get() {
      track()
      return value
    },
    set(newValue: T) {
      clearTimeout(timer)
      timer = setTimeout(() => {
        value = newValue
        trigger()
      }, delay)
    }
  }))
}